package com.houweishi.module.oaDimission.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.oaDimission.domain.OaDimission;
import com.houweishi.module.oaDimission.service.IOaDimissionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 离职申请Controller
 * 
 * @author houweishi
 * @date 2023-07-19
 */
@RestController
@RequestMapping("/module/oaDimission")
public class OaDimissionController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(OaDimissionController.class);
    @Autowired
    private IOaDimissionService oaDimissionService;

    /**
     * 查询离职申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaDimission:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaDimission oaDimission)
    {
        startPage();
        List<OaDimission> list = oaDimissionService.selectOaDimissionList(oaDimission);
        return getDataTable(list);
    }

    /**
     * 导出离职申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaDimission:export')")
    @Log(title = "离职申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaDimission oaDimission)
    {
        List<OaDimission> list = oaDimissionService.selectOaDimissionList(oaDimission);
        ExcelUtil<OaDimission> util = new ExcelUtil<OaDimission>(OaDimission.class);
        util.exportExcel(response, list, "离职申请数据");
    }

    /**
     * 获取离职申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:oaDimission:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oaDimissionService.selectOaDimissionById(id));
    }

    /**
     * 新增离职申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaDimission:add')")
    @Log(title = "离职申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaDimission oaDimission)
    {
        try {
            return oaDimissionService.insertOaDimission(oaDimission);
        } catch (Exception e) {
            LOGGER.error(String.format("新增离职申请失败：%s",e));
            return AjaxResult.error("新增离职申请失败");
        }
    }

    /**
     * 修改离职申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaDimission:edit')")
    @Log(title = "离职申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaDimission oaDimission)
    {
        return toAjax(oaDimissionService.updateOaDimission(oaDimission));
    }

    /**
     * 删除离职申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaDimission:remove')")
    @Log(title = "离职申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaDimissionService.deleteOaDimissionByIds(ids));
    }
}
